<?php
/*************************************************************
*  Copyright notice
*
*  (c) 1999-2009 Christophe Monard (contact@cmonard.fr)
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*  A copy is found in the textfile GPL.txt and important notices to the license
*  from the author is found in LICENSE.txt distributed with these scripts.
*
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Include file extending recordList which extended t3lib_recordList
 * Used specifically for the Web>List module (db_list.php)
 *
 * $Id: class.ux_db_list_extra.inc 2010-08-19 11:16:10Z
 * Revised for TYPO3 4.5.2 March/2011 by Christophe Monard
 * XHTML compliant
 *
 * @author	Christophe Monard <contact@cmonard.fr>
 */
/**
 * [CLASS/FUNCTION INDEX of SCRIPT]
 *
 *
 *
 *   58: class localRecordList extends recordList
 *   72:     function renderListRow($table,$row,$cc,$titleCol,$thumbsCol,$indent=0)
 *  191:     function makecustomButtonList($table, $uid, $language = 0)
 *
 * TOTAL FUNCTIONS: 2
 * (This index is automatically created/updated by the extension "extdeveval")
 *
 */

/**
 * Class for rendering of Web>List module
 *
 * @author	Christophe Monard <contact@cmonard.fr>
 * @package TYPO3
 * @subpackage core
 */
class ux_localRecordList extends localRecordList {
	/**
	 * Rendering a single row for the list
	 *
	 * @param	string		Table name
	 * @param	array		Current record
	 * @param	integer		Counter, counting for each time an element is rendered (used for alternating colors)
	 * @param	string		Table field (column) where header value is found
	 * @param	string		Table field (column) where (possible) thumbnails can be found
	 * @param	integer		Indent from left.
	 * @return	string		Table row for the element
	 * @access private
	 * @see getTable()
	 */
	function renderListRow($table,$row,$cc,$titleCol,$thumbsCol,$indent=0)	{
		$iOut = '';

		if (strlen($this->searchString))	{	// If in search mode, make sure the preview will show the correct page
			$id_orig = $this->id;
			$this->id = $row['pid'];
		}

		if (is_array($row))	{
				// add special classes for first and last row
			$rowSpecial = '';
			if ($cc == 1 && $indent == 0) {
				$rowSpecial .= ' firstcol';
			}
			if ($cc == $this->totalRowCount || $cc == $this->iLimit) {
				$rowSpecial .= ' lastcol';
			}

				// Background color, if any:
			if ($this->alternateBgColors) {
				$row_bgColor = ($cc%2) ? ' class="db_list_normal'.$rowSpecial.'"' : ' class="db_list_alt'.$rowSpecial.'"';
			} else {
				$row_bgColor = ' class="db_list_normal'.$rowSpecial.'"';
			}
				// Overriding with versions background color if any:
			$row_bgColor = $row['_CSSCLASS'] ? ' class="'.$row['_CSSCLASS'].'"' : $row_bgColor;

				// Incr. counter.
			$this->counter++;

				// The icon with link
			$alttext = t3lib_BEfunc::getRecordIconAltText($row,$table);
			$iconImg = t3lib_iconWorks::getSpriteIconForRecord($table, $row, array('title' => htmlspecialchars($alttext), 'style' => ($indent ? ' margin-left: ' . $indent . 'px;' : '')));


			$theIcon = $this->clickMenuEnabled ? $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg,$table,$row['uid']) : $iconImg;

				// Preparing and getting the data-array
			$theData = Array();
			foreach($this->fieldArray as $fCol)	{
				if ($fCol==$titleCol)	{
					$recTitle = t3lib_BEfunc::getRecordTitle($table,$row,FALSE,TRUE);
						// If the record is edit-locked	by another user, we will show a little warning sign:
					if (($lockInfo = t3lib_BEfunc::isRecordLocked($table, $row['uid']))) {
						$warning = '<a href="#" onclick="' . htmlspecialchars('alert(' . $GLOBALS['LANG']->JScharCode($lockInfo['msg']) . '); return false;') . '" title="' . htmlspecialchars($lockInfo['msg']) . '">' .
								t3lib_iconWorks::getSpriteIcon('status-warning-in-use') .
							'</a>';
					}
					$theData[$fCol] = $warning . $this->linkWrapItems($table, $row['uid'], $recTitle, $row);
					
						// Render thumbsnails if a thumbnail column exists and there is content in it:
					if ($this->thumbs && trim($row[$thumbsCol])) {
						$theData[$fCol] .= '<br />' . $this->thumbCode($row,$table,$thumbsCol);
					}

					$localizationMarkerClass = '';
					if (isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
					&& $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] != 0
					&& $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0) {
							// it's a translated record with a language parent
						$localizationMarkerClass = ' localization';
					}
				} elseif ($fCol == 'pid') {
					$theData[$fCol]=$row[$fCol];
				} elseif ($fCol == '_PATH_') {
					$theData[$fCol]=$this->recPath($row['pid']);
				} elseif ($fCol == '_REF_') {
					$theData[$fCol] = $this->createReferenceHtml($table, $row['uid']);
				} elseif ($fCol=='_CUSTOMBUTTONLIST_') { // Custom button list
					$theData[$fCol]=$this->makecustomButtonList($table, $row['uid'], ($row['sys_language_uid']?$row['sys_language_uid']:0));
				} elseif ($fCol == '_CONTROL_') {
					$theData[$fCol]=$this->makeControl($table,$row);
				} elseif ($fCol == '_AFTERCONTROL_' || $fCol == '_AFTERREF_') {
					$theData[$fCol] = '&nbsp;';
				} elseif ($fCol == '_CLIPBOARD_') {
					$theData[$fCol]=$this->makeClip($table,$row);
				} elseif ($fCol == '_LOCALIZATION_') {
					list($lC1, $lC2) = $this->makeLocalizationPanel($table,$row);
					$theData[$fCol] = $lC1;
					$theData[$fCol.'b'] = $lC2;
				} elseif ($fCol == '_LOCALIZATION_b') {
					// Do nothing, has been done above.
				} else {
					$tmpProc = t3lib_BEfunc::getProcessedValueExtra($table, $fCol, $row[$fCol], 100, $row['uid']);
					$theData[$fCol] = $this->linkUrlMail(htmlspecialchars($tmpProc), $row[$fCol]);
					if ($this->csvOutput) {
						$row[$fCol] = t3lib_BEfunc::getProcessedValueExtra($table, $fCol, $row[$fCol], 0, $row['uid']);
					}
				}
			}

			if (strlen($this->searchString))	{	// Reset the ID if it was overwritten
				$this->id = $id_orig;
			}

				// Add row to CSV list:
			if ($this->csvOutput) {
				$this->addToCSV($row,$table);
			}

			// Add classes to table cells
			$this->addElement_tdCssClass[$titleCol]         = 'col-title' . $localizationMarkerClass;
			if (!$this->dontShowClipControlPanels) {
				$this->addElement_tdCssClass['_CONTROL_']       = 'col-control';
				$this->addElement_tdCssClass['_AFTERCONTROL_']  = 'col-control-space';
				$this->addElement_tdCssClass['_CLIPBOARD_']     = 'col-clipboard';
			}
			$this->addElement_tdCssClass['_PATH_']          = 'col-path';
			$this->addElement_tdCssClass['_LOCALIZATION_']  = 'col-localizationa';
			$this->addElement_tdCssClass['_LOCALIZATION_b'] = 'col-localizationb';

				// Create element in table cells:
			$iOut.=$this->addelement(1,$theIcon,$theData,$row_bgColor);

				// Finally, return table row element:
			return $iOut;
		}
	}

	function makecustomButtonList($table, $uid, $language = 0) {
		global $LANG, $SOBE;
		t3lib_div::loadTCA($table); // Initialize:

		//variable de fonctionnement
		$cbl = &$SOBE->modTSconfig['properties']['customButtonList.'];
		$cells = array();
		$L = ($language!=0)?'&L='.$language:'';  # prise en compte de la langue

		// on va parcourir la liste des boutons pour les ajouter
		if (count($cbl)>0) foreach ($cbl as $button)
			if ($button['table'] == $table) {
				$cells[] = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick(($button['id']?$button['id']:($button['altURL']?'':$this->id)),'',t3lib_BEfunc::BEgetRootLine($this->id),'',($button['altURL']?$button['altURL'].$uid:''),($button['additionalParams']!=''?str_replace('###uid###', $uid, $button['additionalParams']):'').$L)).'">'.
							'<img'.t3lib_iconWorks::skinImg($this->backPath,'../'.($button['image']?$button['image']:'typo3conf/ext/cmd_api/res/cbl/'.($button['icon']?$button['icon']:'view_icon.gif')),'width="14" height="14"').' title="'.$button['title.'][$LANG->lang].'" alt="" />'.
							'</a>';
			}

		// on affiche les boutons
		if (count($cells) > 0) {
			// Compile items into a DIV-element:
			return '<!-- CONTROL PANEL: '.$table.':'.$uid.' -->
					<div class="typo3-clipCtrl">'.implode('', $cells).'</div>';
		} else return '';
	}
}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cmd_api/res/cbl/class.ux_localRecordList.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cmd_api/res/cbl/class.ux_localRecordList.php']);
}
?>